﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace CTEA_INDIA
{
     
    public partial class Production_Team : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            populateProductionTeam();

            if (!IsPostBack)
            {
                if (Session["UserID"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
            }

            
        }

        protected void IsNotFutureDate(object sender, ServerValidateEventArgs args)
        {
            DateTime dt;

            bool IsDate = DateTime.TryParse(args.Value.ToString(), out dt);

            if (IsDate)
            {
                if (dt.Date <= DateTime.Now.Date)
                    args.IsValid = true;
                else
                    args.IsValid = false;

            }
        }
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            string PCN = txtProductionCompanyName.Text;
            string Register_with = cmbRegisterWith.Text;
            string Registration_Number = txtRegistrationNumber.Text;
            string Incorporate_Date = txtIncorporateDate.Text;
            string Registration_Address = txtRegistrationAddress.Text;
            string Corporation_Address = txtCorporationAddress.Text;
            string Contact_Number = txtContactNumber.Text;
            string Emailid = txtEmail.Text;
            string _Producer = txtProducer.Text;
            string Associate_Producer = txtAssociateProducer.Text;
            string Investor_Company_Name = txtInvestorCompanyName.Text;
            string Investor_Name = txtInvestorName.Text;
            string Presented_B_N = txtPresentedBannerName.Text;
            string B_Lakh = txtBudget_Lakh.Text;
            string B_Cr = txtBudget_Cr.Text;
            string TOP = cmbtypeOfProduction.Text;
            string TeamId =  BAL.Customers.Production_Team(PCN , Register_with ,Registration_Number ,Incorporate_Date ,
                Registration_Address , Corporation_Address , Contact_Number , Emailid , _Producer , Associate_Producer ,
                Investor_Company_Name , Investor_Name , Presented_B_N , B_Lakh , B_Cr , TOP);






            spnMsgs.Visible = true;
            spnText.InnerHtml = "Your details have been submitted.";

            Session["TeamId"] = TeamId;

            Response.Redirect("Team.aspx");

            populateProductionTeam();
            txtProductionCompanyName.Text = "";
            cmbRegisterWith.SelectedIndex = 0 ;
            txtRegistrationNumber.Text = "";
            txtIncorporateDate.Text = "";
            txtRegistrationAddress.Text = "";
            txtCorporationAddress.Text = "";
            txtContactNumber.Text = "";
            txtEmail.Text = "";
            txtProducer.Text = "";
            txtAssociateProducer.Text = "";
            txtInvestorCompanyName.Text = "";
            txtInvestorName.Text = "";
            txtPresentedBannerName.Text = "";
            txtBudget_Lakh.Text = "";
            txtBudget_Cr.Text = "";
            cmbtypeOfProduction.SelectedIndex = 0;
       }

        public void populateProductionTeam()
        {

            DataSet ds = BAL.Customers.ViewAllProductionTeam();
            gdProductionTeam.DataSource = ds;
            gdProductionTeam.DataBind();

        }


        protected void gdProductionTeam_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gdProductionTeam.PageIndex = e.NewPageIndex;
            populateProductionTeam();
        }


        protected void gdProductionTeam_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //LinkButton lEdit = (LinkButton)e.Row.FindControl("lnkEdit");
                Button update = (Button)e.Row.FindControl("btnUpdate");
                LinkButton lDelete = (LinkButton)e.Row.FindControl("lnkDelete");
                lDelete.CommandArgument = e.Row.RowIndex.ToString();
            }

        }

        protected void lnkView_Click(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;


            int Cid = Convert.ToInt32(gdProductionTeam.DataKeys[row.RowIndex]["ProductionTeamId"]);

            string[] Details = BAL.Customers.GetProductionTeamById(Cid);
            lblPCN.Text = Details[1];
            lblRegWith.Text = Details[2];
            lblRegNo.Text = Details[3];
            lblIncDate.Text = DateTime.Parse(Details[4]).ToShortDateString().ToString();
            lblRegAddr.Text = Details[5];
            lblCorpAddr.Text = Details[6];
            lblContact.Text = Details[7];
            lblEmail.Text = Details[8];
            lblProducerName.Text = Details[9];
            lblAssoProducer.Text = Details[10];
            lblInvCompany.Text = Details[11];
            lblInvName.Text = Details[12];
            lblPBN.Text = Details[13];
            lblBudget.Text = Details[14].ToString() + "lakh to" + Details[15].ToString() + "cr";
            lblTOP.Text = Details[16];
            lblDirectorName.Text=Details[20];
            lblWriter.Text=Details[21];
            lblCastingDirector.Text=Details[22];
            lblMarketingHead.Text=Details[23];
            lblCreatvHead.Text=Details[24];
            lblMusicDirector.Text=Details[25];
            lblDanceDirector.Text=Details[26];
            lblArtDirector.Text=Details[27];
            lblFashionDesigner.Text=Details[28];
            lblExectvProdcr.Text=Details[29];
            lblDop.Text=Details[30];
            lblProductnMgr.Text=Details[31];
            lblAsistantDitr.Text=Details[32];
            lblHeadofMediaMngr.Text=Details[33];
            lblSupplier.Text = Details[34];

            lnkView_ModalPopupExtender.Show();


        }

        protected void lnkEdit_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;
            int Cid = Convert.ToInt32(gdProductionTeam.DataKeys[row.RowIndex]["ProductionTeamId"]);
            string[] Details = BAL.Customers.GetProductionTeamById(Cid);           
            ViewState["Production_Id_Update"] = Cid.ToString(); 
            txtPComanyName.Text = Details[1];
            txtRegisterWith.Text = Details[2];
            txtRegisNumber .Text = Details[3];
            txtIncrpteDte.Text = DateTime.Parse(Details[4]).ToShortDateString().ToString();
            txrRegistrnAddress.Text = Details[5];
            txtCorporteAddrs.Text = Details[6];
            txtContNo.Text = Details[7];
            txtEmailid.Text = Details[8];
            txtProducerName.Text = Details[9];
            txtAscteProducer.Text = Details[10];
            txtInvestrComp.Text = Details[11];
            txtInvestrName.Text = Details[12];
            txtPresetdBannerName.Text = Details[13];
            txtBudgetLak.Text = Details[14].ToString();
            txtBudgetCr.Text = Details[15].ToString();
            cmbEdtTOP.SelectedValue = Details[16].ToString();
            txtDirectrName.Text = Details[20];
            txtWriter.Text = Details[21];
            txtCasting_Dirctr.Text = Details[22];
            txtMarketgHead.Text = Details[23];
            txtCreatvHead.Text = Details[24];
            txtMusicDirtcr.Text = Details[25];
            txtDanceDirtcr.Text = Details[26];
            txtArtDirectr.Text = Details[27];
            txtFashionDesiner.Text = Details[28];
            txtExectvPrdcr.Text = Details[29];
            txtDop.Text = Details[30];
            txtProducnMgr.Text = Details[31];
            txtAssistnDirctr.Text = Details[32];
            txtHMediMgr.Text = Details[33];
            txtSupplr.Text = Details[34];

            ModalPopupExtender1.Show();

        
        }

        protected void lnkDelete_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(gdProductionTeam.DataKeys[row.RowIndex]["ProductionTeamId"]);
            BAL.Customers.DeleteProductionTeamById(Cid);
            populateProductionTeam();
        }
        

        protected void update(object sender, EventArgs e)
        {

            string PCN = txtPComanyName.Text;
            string Register_with = txtRegisterWith.Text;
            string Registration_Number = txtRegisNumber.Text;
            string Incorporate_Date = txtIncrpteDte.Text;
            string Registration_Address = txrRegistrnAddress.Text;
            string Corporation_Address = txtCorporteAddrs.Text;
            string Contact_Number = txtContNo.Text;
            string Emailid = txtEmailid.Text;
            string _Producer = txtProducerName.Text;
            string Associate_Producer = txtAscteProducer.Text;
            string Investor_Company_Name = txtInvestrComp.Text;
            string Investor_Name = txtInvestrName.Text;
            string Presented_B_N = txtPresetdBannerName.Text;
            string B_Lakh = txtBudgetLak.Text;
            string B_Cr = txtBudgetCr.Text;
            string TOP = cmbEdtTOP.Text;
            ///// Team A
            string Director_Name = txtDirectrName.Text;
            string _Writer = txtWriter.Text;
            string Casting_Director = txtCasting_Dirctr.Text;
            string Marketing_Head = txtMarketgHead.Text;
            string Creative_Director = txtCreatvHead.Text;
            string Music_Director = txtMusicDirtcr.Text;
            string Dance_Director = txtDanceDirtcr.Text;
            string Art_Director = txtArtDirectr.Text;
            string Fashion_Designer = txtFashionDesiner.Text;

            ///// Team B
            string Executive_Producer = txtExectvPrdcr.Text;
            string _Dop = txtDop.Text;
            string Production_Manager = txtProducnMgr.Text;
            string Assistant_Director = txtAssistnDirctr.Text;
            string Head_Media_Manager = txtHMediMgr.Text;

            ///// Team C
            string supplier = txtSupplr.Text;
            string production_Team_Id_Update = ViewState["Production_Id_Update"].ToString();
            BAL.Customers.UpdateProductionTeam(PCN, Register_with, Registration_Number, Incorporate_Date,
                Registration_Address, Corporation_Address, Contact_Number, Emailid, _Producer,
                Associate_Producer, Investor_Company_Name, Investor_Name, Presented_B_N,
                B_Lakh, B_Cr,  Director_Name, _Writer, Casting_Director,
                Marketing_Head, Creative_Director, Music_Director, Dance_Director,
                Art_Director, Fashion_Designer, Executive_Producer, _Dop, Production_Manager,
                Assistant_Director, Head_Media_Manager, supplier, production_Team_Id_Update , TOP);

            populateProductionTeam();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string columnName = cmbSearchMain.SelectedValue, Value = "";


            if (cmbSearchMain.SelectedValue.Equals("0")) // view all
            {
                populateProductionTeam();
            }
            else if (cmbSearchMain.SelectedValue.Equals("1")) //PCN
            {
                //columnName = "Company_Name";
                Value = txtSrchName.Text;
                DataSet ds = BAL.Customers.SearchProductionTeam(columnName, Value);
                gdProductionTeam.DataSource = ds;
                gdProductionTeam.DataBind();
            }
            else if (cmbSearchMain.SelectedValue.Equals("2")) //TOP
            {
                //columnName = "Title_Of_Production";
                Value = cmbSrchTOP.Text;

                DataSet ds = BAL.Customers.SearchProductionTeam(columnName, Value);
                gdProductionTeam.DataSource = ds;
                gdProductionTeam.DataBind();
            }
            else if (cmbSearchMain.SelectedValue.Equals("3")) // Contact
            {
                //columnName = "Equipment_Location";
                Value = txtSrchCon.Text;

                DataSet ds = BAL.Customers.SearchProductionTeam(columnName, Value);
                gdProductionTeam.DataSource = ds;
                gdProductionTeam.DataBind();
            }

            else if (cmbSearchMain.SelectedValue.Equals("4")) // Email
            {
                //columnName = "Equipment_Location";
                Value = txtSrchName.Text;

                DataSet ds = BAL.Customers.SearchProductionTeam(columnName, Value);
                gdProductionTeam.DataSource = ds;
                gdProductionTeam.DataBind();
            }


        }

      
    }
}